<template>
  <div class="mod-demo__user" style="overflow-y: scroll;height: 800px;">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item label="用户昵称">
        <el-input v-model="state.dataForm.username" placeholder="请输入用户昵称" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户账号">
        <el-input v-model="state.dataForm.mobile" placeholder="请输入用户账号" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户角色">
        <el-select clearable v-model="state.dataForm.userrole"  placeholder="请选择用户角色">
          <el-option
            v-for="item in dataOPs.userroleOp"
            :key="item"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称">
        <el-input v-model="state.dataForm.projectName" placeholder="请输入项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户状态">
        <el-select clearable v-model="state.dataForm.userstate"  placeholder="请选择用户状态">
          <el-option
            v-for="item in dataOPs.userstateOp"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <!--        v-if="state.hasPermission('demo:user:save')"
                v-if="state.hasPermission('demo:user:delete')"-->
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
              @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <!--              <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="username" label="用户名呢称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="mobile" label="用户账号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="userrole" label="用户角色" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.userrole === 1" size="small" type="danger">施工人员</el-tag>
          <el-tag v-if="scope.row.userrole === 2" size="small" type="info">施工负责人</el-tag>
          <el-tag v-if="scope.row.userrole === 3" size="small" type="success">管理人员</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="listIds" label="参与项目" header-align="center" align="center">
          <template v-slot="scope">
                <template  v-if="null!=scope.row.listIds"  v-for="item in scope.row.listIds">
                  <template  v-if="null != item" >
                     <el-tag size="small" type="info">{{ item.name }}</el-tag>
                  </template>
            </template>
        </template>
      </el-table-column>
      <el-table-column prop="userstate" label="状态" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.userstate === 1" size="small" type="success">启用</el-tag>
          <el-tag v-if="scope.row.userstate === 2" size="small" type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="注册时间" header-align="center" align="center"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <!--          v-if="state.hasPermission('demo:user:update')"
                    v-if="state.hasPermission('demo:user:delete')"-->
          <el-button type="primary" link @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button type="primary" link @click="updatePasswordHandle(scope.row.id)">修改密码</el-button>
          <el-button type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                   :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                   @size-change="state.pageSizeChangeHandle"
                   @current-change="state.pageCurrentChangeHandle"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <!-- 修改密码-->
    <updatePassword ref="updatePasswordRef" @refreshDataList="state.getDataList"></updatePassword>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import {reactive, ref, toRefs} from "vue";
import AddOrUpdate from "./userapp-add-or-update.vue";
import updatePassword from "./user-update-password.vue";

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/sysapp/user/page",
  getDataListIsPage: true,
  exportURL: "/sysapp/user/export",
  deleteURL: "/sysapp/user"
});
const dataOPs = reactive({
  userroleOp:[{label:"全部", value:""},{label:"施工人员", value:1},{label:"施工负责人" ,value:2},{label:"管理人员" ,value:3}],
  userstateOp:[{label:"全部", value:""},{label:"启用", value:1},{label:"禁用" ,value:2}]
})


const state = reactive({...useView(view), ...toRefs(view)});

const addOrUpdateRef = ref();
const addOrUpdateHandle = (row?:{}) => {
  addOrUpdateRef.value.init(row);
};
const updatePasswordRef = ref();
const updatePasswordHandle = (id?: number) => {
  updatePasswordRef.value.init(id);
};
</script>
